package books.ThinkingInJava.src.Chapter11;

public class TestInstanceOf {
    public static void main(String[] args) {
        TestInstanceOf tio = new TestInstanceOf();
        tio.test();
    }

    public void test() {

        B b = new B();
        A a = new A();
        A ba = new B();
        System.out.println("1------------");
        System.out.println(b instanceof B);
        System.out.println(b instanceof A);
        System.out.println(b instanceof Object);
        System.out.println(null instanceof Object);
        System.out.println("2------------");
        System.out.println(b.getClass().isInstance(b));
        System.out.println(b.getClass().isInstance(a));
        System.out.println("3------------");
        System.out.println(a.getClass().isInstance(ba));
        System.out.println(b.getClass().isInstance(ba));
        System.out.println(b.getClass().isInstance(null));
        System.out.println("4------------");
        System.out.println(a instanceof A);
        System.out.println(b instanceof A);
        System.out.println(ba instanceof A);
        System.out.println("5------------");
        System.out.println(a instanceof B);
        System.out.println(b instanceof B);
        System.out.println(ba instanceof B);
        System.out.println("6------------");
        System.out.println(b instanceof Object);
        System.out.println(null instanceof Object);
    }

    class A {
    }

    class B extends A {
    }
}
